package edu.neu.cs6515.xml;

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.adapters.XmlJavaTypeAdapter;

import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
 * Representation of a Tile in the Ingenious game, just two colors, no coordinates
 */
@XmlRootElement
@NoArgsConstructor
@EqualsAndHashCode
@ToString
public final class Tile {
    
    private  IngeniousColor c0;
    private  IngeniousColor c1;

    /**
     * Initializes the Tile with the two given colors
     * @param color0 col0
     * @param color1 col1
     */
    public Tile(final IngeniousColor color0, final IngeniousColor color1) {
        this.c0 = color0;
        this.c1 = color1;
    }
    
    /**
     * @param tile tile to compare
     * @return true iff the two tiles have the same two colors
     */
    public boolean tileSameColorsAs(final Tile tile) {
        if (tile.getC0() == this.c0) {
            return tile.getC1() == this.c1;
        } else if (tile.getC0() == this.c1) {
            return tile.getC1() == this.c0;
        }
        return false;
    }
    
    @XmlAttribute(required = true)
    @XmlJavaTypeAdapter(IngeniousColorAdapter.class) 
    public IngeniousColor getC0() {
        return c0;
    }

    public void setC0(final IngeniousColor c0) {
        this.c0 = c0;
    }

    @XmlAttribute(required = true)
    @XmlJavaTypeAdapter(IngeniousColorAdapter.class) 
    public IngeniousColor getC1() {
        return c1;
    }

    public void setC1(final IngeniousColor c1) {
        this.c1 = c1;
    }
}
